<%@page import="Domain.Website"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<jsp:useBean id="currentUser" scope="session" class="Domain.UserBean" />
<jsp:useBean id="user" class="Domain.UserBean" scope="page"/>
<jsp:setProperty name="user" property="*"/>

<form method="POST" action="login.jsp">
    Username:<input type="text" name="userName"/><br/>
    Password:<input type="password" name="password" />
    <input type="submit" value="Login"/>
</form>

<%
    if(user.getuserName() != null){
        Website web = Website.getInstance();
        currentUser.copy(user);
        int userID = web.getUserID(currentUser.getuserName());
        currentUser.setuserId(userID);
        response.sendRedirect("blogview.jsp");
    }
    else if(request.getParameter("login") != null && request.getParameter("login").equals("badlogin")){
        out.print("Invalid username or password");
    }
    else if(request.getParameter("login") != null && request.getParameter("login").equals("logout")){
        currentUser.setuserName(null);
        response.sendRedirect("blogview.jsp");
    }
%>